﻿using AllanXingCommonLibrary;
using cnBlogs.Common;
using cnBlogs.DataModel;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace cnBlogs.ViewModel
{
    class NewsDetailViewModel : GetFeedsBase
    {
        private NewsDetailModel _NewsDetailInfo = new NewsDetailModel();

        public NewsDetailModel NewsDetailInfo
        {
            get { return _NewsDetailInfo; }
            set { this.SetProperty(ref _NewsDetailInfo, value); }
        }

        private NewsInfo _newsinfo;

        public NewsDetailViewModel(NewsInfo newsinfo)
        {
            _newsinfo = newsinfo;
        }
        protected override void Parse(string feed)
        {
            GroupCollection gpcontant = Regex.Match(feed, "<div id=\"news_body\">(?<Contant>.*?)</div>.*?<div id=\"news_otherinfo\">").Groups;
            GroupCollection gptitle = Regex.Match(feed, "<div id=\"news_title\".*?<a href=\"" + _newsinfo.Link + "\">(?<Title>.*?)</a>").Groups;
            NewsDetailModel adm = new NewsDetailModel();
            adm.ArticleContent = gpcontant["Contant"].Value;
            adm.ArticleTitle = gptitle["Title"].Value;
            NewsDetailInfo=adm;
        }

        protected override string GetUrl()
        {
            return _newsinfo.Link;
        }
    }
}
